<template>
    <div class="bottom-bar">
        <div class="check-button">
            <div @click="checkclick" class="icon-selector" :class="{'selector-active': isSelectAll}" >
        <img v-show="isSelectAll" src="~/assets/img/cart/tick.svg" alt="">
      </div>
      <span>全选</span>
        </div>
        <div class="hej">
            合计:￥{{totalPrice}}
        </div>
        <div class="shulian">
            去计算:({{checkLength}})
        </div>
    </div>
</template>

<script>
export default {
    name:'CategoryBa',
    computed:{
        //总价格，保持两位小数
        totalPrice(){
            return this.$store.state.cartList.filter(item=>{
                return item.xuanz
            }).reduce((prevalue,item)=>{
                return prevalue+item.price*item.count
            },0).toFixed(2)
        },
        //判断选中的长度
        checkLength(){
            return this.$store.state.cartList.filter(item=>item.xuanz).length
        },
         //判断是否选中和不选中
        isSelectAll(){
           if(this.$store.state.cartList.length===0){
               return false
           }else{
                return !(this.$store.state.cartList.filter(item=>!item.xuanz).length)
           }
        }
    },
    methods:{
        //判断是否全选选中和不全选选中
        checkclick(){
            if(this.isSelectAll){
                this.$store.state.cartList.forEach(item =>item.xuanz=false);
            }else{
                 this.$store.state.cartList.forEach(item =>item.xuanz=true);
            }
        }
    }
}
</script>

<style scoped>
.bottom-bar{
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 49px;
    height: 40px;
    background-color: rgb(241, 240, 240);

}
.icon-selector {
    position: relative;
    margin: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #ccc;
    cursor: pointer;
   
  }
   .selector-active {
    background-color: #ff8198;
    border-color: #ff8198;

  }
  .check-button{
    display: flex;
    margin-top: 10px;
    margin-left: 5px;
    color: #333;
  }
  span{
      margin-left: 3px;
      margin-top: -3px;
  }
  .hej{
      margin-left: 40px;
      flex: 1;
      line-height: 40px;
      color: #333;
      
  }
  .shulian{
      width: 100px;
      background-color: rgb(233, 21, 57);
      line-height: 40px;
      text-align: center;
      color: #fff;
  }
  
</style>